Travis CI and RVM

2011-10-22

After trying hooking up ooc and Tcl, waiting for the Self guys to respond, and exploring Travis CI, I figured I'd share my short story with you.

The documentation of Travis recommends using Bundler for managing dependencies of your project.

Since I happen to like the way gemsets work, and Travis is using RVM to manage the different Ruby versions, I figured I could just call rvm gemset import .gems and everything would be peachy.

For some reason, the rvm environment becomes broken once Travis starts your tests, so you have to load it manually again, and then import your gemset.

I used this approach with Innate, and here's the .travis.yml

---
script: 'RUBYOPT=-rubygems rake bacon'

before_script:
  - "./.load_gemset"

rvm:
  - 1.8.7
  - 1.9.2
  - 1.9.3
  - rbx
  - rbx-2.0
  - ree
  - jruby

notifications:
  email:
    - mf@rubyists.com

branches:
  only:
    - master

And also the .load_gemset executable referenced above:

#!/bin/bash

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
[[ -s .gems ]] && rvm gemset import .gems

Please note that i do not use bash -e as they recommend, it would terminate the script before it comes to importing the gemset due to failure of loading .rvmrc, as RVM asks the user and we have no tty access. That's no big issue, as we will notice what's going wrong when our specs don't pass anymore anyway.

That's all, happy Continuous Integration.